package com.Servlet;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jdbc.*;

public class AddCheckinfoRow {

	public static void main(String[] args) {
		
		
		
		
		// int i=1;
		// for(i=1;i<=90;i++) {
		// String alter = "alter table check_info add column check"+i+" varchar(50)
		// character set utf8 ";
		// try {
		// Jdbc a = new Jdbc(alter);
		// } catch (ClassNotFoundException | SQLException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		
		
		
		
		
//		String stuid = "2";
//		String find_checkdate = "2018-01-22未出勤";
//		String check_date = "2018-01-22";
//		String select = "select * from check_info where stuid='" + stuid + "'";
//		try {
//			Jdbc sci = new Jdbc();
//			sci.Jdbc_Q2(select);
//			sci.rs.first();// 结果集
//			String checkdate;
//			for (int i = 1; i <= 90; i++) {
//				checkdate = sci.rs.getString("check" + i);
//				System.out.println(checkdate);
//				
//				if (checkdate!=null&&checkdate.equals(find_checkdate)) {
//					String uci = "update check_info set check" + i + "='" + check_date + "已补' where stuid='" + stuid
//							+ "'";
//				Jdbc j1 = new Jdbc(uci);
//			    break;
//				}
//				
//			}
//		} catch (ClassNotFoundException | SQLException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
		
		
//		ResultSet rs;
//		String checkdate="2018-01-20";
//		String find = "select * from SH0021check where date='" + checkdate + "'";
//		System.out.println(find);
//		Jdbc j = new Jdbc();
//		
//		
//		try {
//			j.Jdbc_Q2(find);
//		} catch (ClassNotFoundException | SQLException e) {
//			// TODO Auto-generated catch block
//			
//			System.out.println("hahah");
//		}
		
		
		
//		String classname="1";
//		String centername="SH002";
//		String checkdate="2018-01-22";
//		 String select = "select * from checkdate where classname='"+classname+"' and centername='"+centername+"' and date='"+checkdate+"'";
//		System.out.println(select);	
//		 try {
//				Jdbc checkdate1 = new Jdbc();
//				checkdate1.Jdbc_Q2(select);
//				checkdate1.rs.first();
//				String c = checkdate1.rs.getString("classname");
//			    System.out.println(select);
//				if(c!=null&&c.equals(classname)){
//					//表示这个日期已经检查过了
//					System.out.println("haha");
//					
//				}
//			} catch (ClassNotFoundException | SQLException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//			}
		String centername="SH001";
		String classname="测试一班";
		int columns=0;
		String findtable="select * from information_schema.columns where table_name='"+centername+classname+"check'";
		System.out.println(findtable);
		Jdbc ft = new Jdbc();
		List<String> cn = new ArrayList<String>();//用于存储表格中的列名
		try {
			ft.Jdbc_Q2(findtable);
			int i=1;
			while(ft.rs.next()) {
				columns++;
				if(ft.rs.getString("is_nullable") .equals("YES")) {
				cn.add(ft.rs.getString("column_name"));
				}
				//System.out.println(ft.rs.getString("is_nullable"));
			}
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String find = "";
		
       for(String s: cn) {
    	   find = find+s + ",";
    	   
    	   

       }
       find=find.substring(0,find.length()-1);//将最后一个逗号去掉
       find = find + " ";//给最后一个列名后面加上空格，使得查询语句正常
       //find =find.Remove(0,1);
       System.out.println(find);
       String find1="select stuid, stuname, centername ,classname, "+find+"from "+centername+classname+"check"+" ";
      
       System.out.println(find1);
	}

}
